import 'package:flutter/material.dart';
import 'package:repair_pda/pages/history/history_page.dart';
import 'package:repair_pda/pages/home/home_page.dart';
import 'package:repair_pda/pages/statistics/statistics_page.dart';

class TabNavigator extends StatefulWidget {
  const TabNavigator({super.key});

  @override
  State<TabNavigator> createState() => _TabNavigatorState();
}

class _TabNavigatorState extends State<TabNavigator> {
  int _currentPageIndex = 0;
  final _defaultColor = Colors.grey;
  final _activeColor = Colors.blue;
  final PageController _controller = PageController(
    initialPage: 0, // 默认打开第一个页面
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _controller,
        children: [HomePage(),HistoryPage(),StatisticsPage()],
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentPageIndex,
        onTap: (index){
          _controller.jumpToPage(index);
          setState(() {
            _currentPageIndex = index;
          });
        },
        items: [
          _bottomNavigatorItem('首页', Icons.home, 0),
          _bottomNavigatorItem('历史记录', Icons.search, 1),
          _bottomNavigatorItem('效率统计', Icons.camera, 2),
        ],
      ),
    );
  }

  _bottomNavigatorItem(String title, IconData icon, int index){
    return BottomNavigationBarItem(
        icon: Icon(icon,color: _defaultColor),
        activeIcon: Icon(icon, color: _activeColor),
        label: title
    );
  }
}
